﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Data.SqlTypes;
using System.Collections;
using System.Data.SqlServerCe;

namespace ProjetoFase2
{
    public class Residence
    {
        private string address, client, topology;
        private int resi_id, cooling, heating, isolation;
        private string coverage, glasses;
        private int[] version;
        private int category;
        private string district;
        private string visit_time;
        private int approved;

        public string Visit_time
        {
            get { return visit_time; }
            set { visit_time = value; }
        }

        public int Approved
        {
            get { return approved; }
            set { approved = value; }
        }

        public string District
        {
            get { return district; }
            set { district = value; }
        }

        public int Category
        {
            get { return category; }
            set { category = value; }
        }

        public int Resi_id
        {
            get { return resi_id; }
            set { resi_id = value; }
        }

        public int[] Version
        {
            get { return version; }
            set { version = value; }
        }

        public int Isolation
        {
            get { return isolation; }
            set { isolation = value; }
        }

        public int Heating
        {
            get { return heating; }
            set { heating = value; }
        }

        public string Topology
        {
            get { return topology; }
            set { topology = value; }
        }

        public string Client
        {
            get { return client; }
            set { client = value; }
        }

        public string Address
        {
            get { return address; }
            set { address = value; }
        }

        public int Cooling
        {
            get { return cooling; }
            set { cooling = value; }
        }

        public string Glasses
        {
            get { return glasses; }
            set { glasses = value; }
        }

        public string Coverage
        {
            get { return coverage; }
            set { coverage = value; }
        }

        public Residence(DataTableReader dtReader)
        {
            resi_id = dtReader.GetInt32(0);
            address = dtReader.GetString(1);
            district = dtReader.GetString(2);
            client = dtReader.GetString(3);
            category = dtReader.GetInt32(4);

            // read time
            try {
                visit_time = dtReader.GetDateTime(5).ToShortTimeString();
            }
            catch(Exception ex)
            {
                visit_time = dtReader.GetString(5);
            }

            if (!dtReader.IsDBNull(6))
            {
                topology = dtReader.GetString(6);
                cooling = dtReader.GetInt32(7);
                heating = dtReader.GetInt32(8);
                isolation = dtReader.GetInt32(9);
                coverage = dtReader.GetString(10);
                glasses = dtReader.GetString(11);
                try
                {
                    approved = dtReader.GetInt32(12);
                }
                catch(Exception)
                {
                    approved = 0;
                }
            }
        }

        public Residence(SqlCeDataReader dtReader)
        {
            resi_id = dtReader.GetInt32(0);
            address = dtReader.GetString(1);
            district = dtReader.GetString(2);
            client = dtReader.GetString(3);
            category = dtReader.GetInt32(4);

            // read time
            try
            {
                visit_time = dtReader.GetDateTime(5).ToShortTimeString();
            }
            catch (Exception)
            {
                visit_time = dtReader.GetString(5);
            }

            if (!dtReader.IsDBNull(6))
            {
                topology = dtReader.GetString(6);
                cooling = dtReader.GetInt32(7);
                heating = dtReader.GetInt32(8);
                isolation = dtReader.GetInt32(9);
                coverage = dtReader.GetString(10);
                glasses = dtReader.GetString(11);
                try
                {
                    approved = dtReader.GetInt32(12);
                }
                catch (Exception)
                {
                    approved = 0;
                }
            }

        }

    }
}